<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Adv_Page_Model extends CI_Model{
    function __construct()
    {
        parent::__construct();
    }
    function delete($id){
          $this->db->where('adv_page_id',$id);
          $query = $this->db->delete('adv_page');
          if($query){
              $this->db->where('adv_page_id',$id);
              $query = $this->db->delete('adv_position');
              return true;
          }else{
              return false;
          }
    }
   function saveData($adv_page_id,$data){
        if($adv_page_id!=0){
            $this->db->where('adv_page_id',$adv_page_id);
            if($this->db->update('adv_page',$data)){
                 return true;
            }else{
                 return false;
            }
        }else{
            if($this->db->insert('adv_page',$data)){
                return true;

            }else{
                return false;
            }
        }
    }
    function getAdvPageByID($id)
    {
        $this->db->where('adv_page_id',$id);
        return $this->db->get('adv_page')->row();
    }
    function getNumAdvPage($arr_search){
        /*Begin search*/
        switch($arr_search['field_search'])
        {
            case 'adv_page_code':
                $this->db->like('adv_page_code',$arr_search['key_search']);
            break ;
            case 'adv_page_name':
                $this->db->like('adv_page_name',$arr_search['key_search']);
            break ;
        }
        /*End search*/
        //$this->db->where('bl_active',1);
        $query = $this->db->get('adv_page');
        return $query->num_rows();
    }
    function getAllAdvPage($num,$offset,$arr_search)
    {
        /*Begin search*/
        switch($arr_search['field_search'])
        {
            case 'adv_page_code':
                $this->db->like('adv_page_code',$arr_search['key_search']);
            break ;
            case 'adv_page_name':
                $this->db->like('adv_page_name',$arr_search['key_search']);
            break ;
        }
        /*End search*/
        //$this->db->where('bl_active',1);
        $query = $this->db->get('adv_page',$num,$offset);
        return $query->result();
    }  
  }
?>
